package com.sfy.yxy.doctor.base;

import android.os.Bundle;
import android.view.Window;
import android.widget.Toolbar;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.sfy.yxy.doctor.R;


import org.greenrobot.eventbus.EventBus;

import butterknife.ButterKnife;

/**
 * @author :creat by Xia燚
 * 时间：2021/9/8
 * 邮箱：XiahaotianV@163.com
 **/
public abstract class BaseActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        doBeforeSetContentView();
        setContentView(getLayoutId());
        // 初始化View注入
        ButterKnife.bind(this);
        initView();
        initData();
        EventBus.getDefault().register(this);
    }


    /**
     * 设置layout前的配置
     */
    private void doBeforeSetContentView() {
        // 隐藏标题栏
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        //把actvity放到栈中管理
        ActivityCollector.addActivity(this);

    }


    /**
     * 获取布局文件
     */
    public abstract int getLayoutId();

    /**
     * 初始化控件
     */
    protected abstract void initView();

    /**
     * 初始数据
     */
    protected abstract void initData();


    public void initToolBar(Toolbar toolbar, String title, int icon) {
        toolbar.setTitle(title);// 标题的文字需在setSupportActionBar之前，不然会无效
        toolbar.setNavigationIcon(icon);
        setActionBar(toolbar);
        toolbar.setTitleTextColor(getResources().getColor(R.color.white));
        toolbar.setPopupTheme(R.style.ToolBarPopupThemeDay);
    }

    //销毁所有的Activity
    public void DestroyAllActivity() {
        ActivityCollector.finshAll();
    }


    @Override
    protected void onDestroy() {
      //  Glide.with(this.getApplicationContext()).pauseRequests();
        EventBus.getDefault().unregister(this);
        super.onDestroy();
    }
}
